package com.admin.testproject.activity

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.view.GravityCompat
import android.support.v7.app.AppCompatDelegate
import android.support.v7.widget.GridLayoutManager
import android.util.Log
import android.view.MenuItem
import com.admin.testproject.BaseActivity
import com.admin.testproject.R
import com.admin.testproject.adapter.MainAdapter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity() {
    override fun bindLayout(): Int {
        return R.layout.activity_main
    }

    override fun bindData() {
        setSupportActionBar(tb_bar)
        supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        fab.setOnClickListener {
            //            Snackbar.make(it,"hahha",Snackbar.LENGTH_SHORT)
//                .setAction("uuu") {
//                    Toast.makeText(this,"iiiiii",Toast.LENGTH_SHORT).show()
//                }.show()
        }

        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)
        list.add(R.mipmap.ic_launcher)

        val adapter= MainAdapter(this)
        rlv.layoutManager=GridLayoutManager(this,2)
        rlv.adapter=adapter
        adapter.upData(list)

        nv.setNavigationItemSelectedListener {
            Log.d("*************",it.itemId.toString())
            Log.d("*************",it.title.toString())
            drawer.closeDrawers()
            when(it.itemId){
                R.id.item_01 ->{
                    Log.d("*********","11111111111111")
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
                }
                R.id.item_02 ->{
                    Log.d("*********","22222222222")
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
                }
            }
            true
        }
    }

    override fun bindEvent() {

    }

    val list=ArrayList<Int>()

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        when(item?.itemId){
            android.R.id.home->{
                drawer.openDrawer(GravityCompat.START)
                return true
            }
        }
        return super.onOptionsItemSelected(item)
    }
}
